//
//  MYInfoViewController.m
//  IngCard
//
//  Created by kf on 2017/10/24.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "MYInfoViewController.h"
#import "YDAccountManager.h"
#import "YD3rdInfoProfileTableViewCell.h"
#import "YD3rdInfoSectionTableViewCell.h"
#import "YDUserExperienceTableViewCell.h"
#import "YDUserBaseInfoEditViewController.h"
#import "YDUserExperienceEditViewController.h"

typedef enum : NSUInteger {
    kBaseInfo,
    kJobInfo,
    kEducationInfo,
} kActions;

@interface MYInfoViewController ()

@end

@implementation MYInfoViewController

-(void) viewDidLoad
{
    [super viewDidLoad];
    self.title = STRING.info;
}
- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Dark];
    [THEME renderNavigationBar:self style:YDNavigationStyle_Gray];
}

-(void) initDataSource
{
    [self.dataSource addDataSource:[YD3rdInfoProfileCellDataSource class]
                         atSection:0
                            config:^(YD3rdInfoProfileCellDataSource * dataSource)
     {
         dataSource.name = ACCOUNT.account.name;
         dataSource.title = ACCOUNT.account.occupation;
         dataSource.job = ACCOUNT.account.company;
         dataSource.location = ACCOUNT.account.location;
         dataSource.email = ACCOUNT.account.email;
         dataSource.headerImageUrl =  [NSURL URLWithString:ACCOUNT.account.head_pic];
         
         dataSource.tag = kBaseInfo;
     }];
    
    [self.dataSource addDataSource:[YD3rdInfoSectionCellDataSource class]
                         atSection:1
                            config:^(YD3rdInfoSectionCellDataSource* dataSource)
     {
         dataSource.titleImage = UIImageMake(@"user_3rd_info_job");
         dataSource.title = STRING.user_3rd_info_job;
         dataSource.tag = kJobInfo;
     }];
    
    for (YDAccountOccupation *occupation in ACCOUNT.account.occupations) {
        
        [self.dataSource addDataSource:[YDUserExperienceCellDataSource class]
                             atSection:1 config:^(YDUserExperienceCellDataSource* dataSource)
         {
             dataSource.title = occupation.title;
             dataSource.detail = occupation.companyName;
             dataSource.content = NSStringFormat(@"%@年%@月 - %@年%@月",
                                                 occupation.startYear,occupation.startMonth,
                                                 occupation.endYear,occupation.endMonth);
         }];
    }
    
    
    [self.dataSource addDataSource:[YD3rdInfoSectionCellDataSource class]
                         atSection:2
                            config:^(YD3rdInfoSectionCellDataSource* dataSource)
     {
         dataSource.titleImage = UIImageMake(@"user_3rd_info_job");
         dataSource.title = @"教育背景";
         dataSource.tag = kEducationInfo;
     }];
    
    for (YDAccountEducation *education in ACCOUNT.account.educations) {
        
        [self.dataSource addDataSource:[YDUserExperienceCellDataSource class]
                             atSection:2 config:^(YDUserExperienceCellDataSource* dataSource)
         {
             dataSource.title = education.schoolName;
             dataSource.detail = education.major;
             dataSource.content = NSStringFormat(@"%@- %@",
                                                 education.startTime,education.endTime);
         }];
    }
    
    [self.dataSource addDataSource:[YD3rdInfoSectionCellDataSource class]
                         atSection:3
                            config:^(YD3rdInfoSectionCellDataSource* dataSource)
     {
         dataSource.titleImage = UIImageMake(@"user_3rd_info_web");
         dataSource.title = STRING.user_3rd_info_url;
         dataSource.content = ACCOUNT.account.public_profile_url;
     }];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    YDBaseTableViewCellDataSrouce *dataSource = [self.dataSource dataSourceAtIndexPath:indexPath];
    
    switch (dataSource.tag) {
        case  kBaseInfo:
        {
            YDUserBaseInfoEditViewController *vc = [YDUserBaseInfoEditViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case kJobInfo:
        {
            YDUserExperienceEditViewController *vc = [YDUserExperienceEditViewController new];
            vc.model = kJob;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case kEducationInfo:
        {
            YDUserExperienceEditViewController *vc = [YDUserExperienceEditViewController new];
            vc.model = kEducation;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

@end
